# This file is part of BlackArch Linux ( https://www.blackarch.org/ ).
# See COPYING for license details.

pkgname=fastnetmon
pkgver=v1.2.8.r40.ga2d2d0d7
pkgrel=1
pkgdesc='High performance DoS/DDoS load analyzer built on top of multiple packet capture engines.'
url='https://github.com/pavel-odintsov/fastnetmon'
arch=('x86_64')
groups=('blackarch' 'blackarch-defensive' 'blackarch-sniffer')
license=('GPL')
depends=('binutils' 'boost' 'hiredis' 'json-c' 'libpfring' 'log4cpp' 'luajit'
         'mongo-c-driver' 'ndpi' 'numactl' 'pfring-dkms' 'boost-libs'
         'capnproto' 'grpc')
makedepends=('binutils' 'boost' 'cmake' 'git' 'hiredis' 'libpfring' 'log4cpp'
             'luajit' 'make' 'mongo-c-driver' 'ndpi' 'numactl' 'libbpf')
source=("git+https://github.com/pavel-odintsov/$pkgname.git"
        'CMakeLists.txt.patch')
sha512sums=('SKIP'
            '091e20d9b57ef590893dc8a710ca632cc4e2559954d9458e681eee473966a6c913e30b01c2bbaae782ed862a17d2b506049520fc05afa49fe1db47c8e7301f07')

pkgver() {
  cd $pkgname

  git describe --long --tags | sed 's/\([^-]*-g\)/r\1/;s/-/./g'
}

prepare() {
  cd "$pkgname/src"

  #patch < ../../CMakeLists.txt.patch
}

build() {
  cd "$pkgname/src"

  mkdir -p build
  cd build

  cmake -DCMAKE_INSTALL_PREFIX=/usr ..
  make
}

package() {
  cd $pkgname

  install -dm 755 "$pkgdir/usr/lib"

  install -Dm 644 -t "$pkgdir/usr/share/doc/$pkgname" README.md
  install -Dm 644 LICENSE "$pkgdir/usr/share/licenses/$pkgname/LICENSE"

  cd src/build

  make DESTDIR="$pkgdir" install

  # fix for conflicting files

  cp -r --no-preserve=owner "$pkgdir/lib/systemd" "$pkgdir/usr/lib"
  cp -r --no-preserve=owner "$pkgdir/usr/sbin/$pkgname" "$pkgdir/usr/bin"

  rm -rf "$pkgdir/lib"
  rm -rf "$pkgdir/usr/sbin"

  mv "$pkgdir/usr/bin/${pkgname}_client" "$pkgdir/usr/bin/$pkgname-client"
}

